package io.adrainty.bolee.trade.utils;

import com.alipay.api.DefaultAlipayClient;
import com.alipay.easysdk.kernel.Config;
import io.adrainty.bolee.trade.models.entity.PayChannelEntity;

/**
 * @author AdRainty
 * @version V1.0.0
 * @since 2025/8/31 下午11:48
 */
public class AliPayUtils {

    private AliPayUtils() {
    }

    public static Config getAliPayConfig(PayChannelEntity payChannelEntity) {
        Config config = new Config();
        config.protocol = "https";
        config.gatewayHost = payChannelEntity.getDomain();
        config.signType = "RSA2";
        config.appId = payChannelEntity.getAppId();
        config.merchantPrivateKey = payChannelEntity.getMerchantPrivateKey();
        config.alipayPublicKey = payChannelEntity.getPublicKey();
        config.notifyUrl = payChannelEntity.getNotifyUrl();
        config.encryptKey = payChannelEntity.getEncryptKey();
        return config;
    }

    public static DefaultAlipayClient createAlipayClient(PayChannelEntity payChannelVO) {
        return new DefaultAlipayClient("https://" + payChannelVO.getDomain() + "/gateway.do",
                payChannelVO.getAppId(),
                payChannelVO.getMerchantPrivateKey(),
                "json",
                "GBK",
                payChannelVO.getPublicKey(),
                "RSA2");
    }

}
